/**
 * =====================================================================================
 *       @file  ngx_connection.h
 *      @brief  
 *
 *  Detailed description starts here.
 *
 *   @internal
 *     Created  2012年05月08日 21时39分21秒 
 *    Revision  1.0.0.0
 *    Compiler  gcc/g++
 *
 *     @author  luis
 * =====================================================================================
 */

#ifndef _NGX_CONNECTION_H_INCLUDED_
#define _NGX_CONNECTION_H_INCLUDED_

#include "ngx_config.h"
#include "ngx_core.h"
#include "ngx_socket.h"
#include "ngx_string.h"
#include "ngx_event.h"
#include "ngx_cycle.h"
#include "ngx_os.h"

typedef struct ngx_listening_s ngx_listening_t;

struct ngx_listening_s 
{
    ngx_socket_t                fd;
    struct sockaddr            *sockaddr;
    socklen_t                   socklen;
    size_t                      addr_text_max_len;
    ngx_str_t                   addr_text;

    int                         type;
    int                         backlog;

    ngx_connection_handler_pt   handler;

    ngx_connection_t           *connection;

    size_t                      pool_size;


    
    unsigned                    open:1;

    unsigned                    listen:1;
};

struct ngx_connection_s 
{
    void                *data;
    ngx_event_t         *read;
    ngx_event_t         *write;

    ngx_recv_pt          recv;
    ngx_send_pt          send;
    ngx_recv_chain_pt     recv_chain;
    ngx_send_chain_pt     send_chain;

    ngx_socket_t         fd;    
    ngx_listening_t     *listening;

    struct sockaddr     *local_sockaddr;
    socklen_t            socklen;

    ngx_pool_t          *pool;

    struct sockaddr     *sockaddr;
    ngx_str_t            addr_text;
};

ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle);

ngx_connection_t *ngx_get_connection(int s);
void ngx_free_connection(ngx_connection_t *c);

#endif
